package com.diandian.backend.client.controller;

import com.diandian.backend.client.service.ClientPermissionService;
import com.diandian.backend.client.service.ClientService;
import com.diandian.base.boot.starter.response.BaseResult;
import com.diandian.backend.client.param.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/client/permission/relation")
public class ClientPermissionController {

    @Autowired
    private ClientService clientService;

    @Autowired
    private ClientPermissionService clientPermissionService;

    /**
    * 1. 分页查询
    */
//    @PostMapping("/page")
//    public BaseResult page(@RequestBody ClientClientPermissionPageParam param) {
//        param.check();
//        return new BaseResult(0, "success", clientPermissionService.page(param.toDTO()));
//    }

    /**
     * 2. 查询详情
     */
//    @PostMapping("/detail")
//    public BaseResult getDetail(@RequestBody ClientClientPermissionDetailParam param) {
//        return new BaseResult(0, "success", clientPermissionService.getDetail(param.toDTO()));
//    }

    /**
     * 3. 根据数据id更新数据
     */
//    @PostMapping("/updateById")
//    public BaseResult updateById(@RequestBody ClientClientPermissionUpdateByIdParam param) {
//        clientPermissionService.updateById(param.toDTO());
//        return new BaseResult(0, "success", null);
//    }

    /**
     * 4. 根据数据id删除数据
     */
    @PostMapping("/delete")
    public BaseResult delete(@RequestBody ClientClientPermissionDeleteParam param) {
        param.check();
        clientPermissionService.delete(param.getClientId(), param.getPermissionId(), param.getRemark());
        // 同步到redis
        clientService.manualCache(param.getClientId());
        return new BaseResult(0, "success", null);
    }

    /**
     * 5. 新增
     */
    @PostMapping("/add")
    public BaseResult add(@RequestBody ClientClientPermissionAddParam param) {
        param.check();
        clientPermissionService.add(param.toDTO());
        // 同步到redis
        clientService.manualCache(param.getClientId());
        return new BaseResult(0, "success", null);
    }

    /**
     * 7. 列表查询
     */
    @PostMapping("/list")
    public BaseResult list(@RequestBody ClientClientPermissionListParam param) {
        return new BaseResult(0, "success", clientPermissionService.getList(param.toDTO()));
    }

    /**
     * 查询某个clientId的权限信息
     */
    @GetMapping("/permissions/clientId")
    public BaseResult queryPermissions(@RequestParam(value = "clientId") String clientId) {
        return new BaseResult(0, "success", clientPermissionService.getPermissions(clientId));
    }

}